#ifndef __SHT31_H
#define __SHT31_H
#include "n32l40x.h"

#define SHT3X_SCL_CLK_EN()        RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE)
#define SHT3X_SDA_CLK_EN()        RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE)
#define SHT3X_SCL_PIN             GPIO_PIN_12
#define SHT3X_SDA_PIN             GPIO_PIN_11
#define SHT3X_SCL_GPIO            GPIOA
#define SHT3X_SDA_GPIO            GPIOA

#define SHT3X_ADDRESS                     0x88
#define SHT3X_ADDRESS_WRITE               0x88
#define SHT3X_ADDRESS_READ                0x89
typedef struct
{
	float temperature;
	float humidity;
	
	short temp_integer;
	short temp_decimal;
	char humi_integer;
	char humi_decimal;
	
	//uint8_t decimal_places;//小数位数 
}SHT3X_t;
	

//温湿度校正值
//  #define  TEM_CHEAK_VALUE           3//一天后早晨9点温度要再加1湿度再加3  2 13
//  #define  RH_CHEAK_VALUE            10
#define  TEM_CHEAK_VALUE           2
#define  RH_CHEAK_VALUE            13



// Sensor Commands    
typedef enum{
    CMD_READ_SERIALNBR  = 0x3780, // read serial number       
    CMD_READ_STATUS     = 0xF32D, // read status register     
    CMD_CLEAR_STATUS    = 0x3041, // clear status register    ?
    CMD_HEATER_ENABLE   = 0x306D, // enabled heater           
    CMD_HEATER_DISABLE  = 0x3066, // disable heater           
    CMD_SOFT_RESET      = 0x30A2, // soft reset               ?
    CMD_MEAS_CLOCKSTR_H = 0x2C06, // meas. clock stretching, high rep.
    CMD_MEAS_CLOCKSTR_M = 0x2C0D, // meas. clock stretching, medium rep.
    CMD_MEAS_CLOCKSTR_L = 0x2C10, // meas. clock stretching, low rep.
    CMD_MEAS_POLLING_H  = 0x2400, // meas. no clock stretching, high rep.
    CMD_MEAS_POLLING_M  = 0x240B, // meas. no clock stretching, medium rep.
    CMD_MEAS_POLLING_L  = 0x2416, // meas. no clock stretching, low rep.
    CMD_MEAS_PERI_05_H  = 0x2032, // meas. periodic 0.5 mps, high rep.
    CMD_MEAS_PERI_05_M  = 0x2024, // meas. periodic 0.5 mps, medium rep.
    CMD_MEAS_PERI_05_L  = 0x202F, // meas. periodic 0.5 mps, low rep.
    CMD_MEAS_PERI_1_H   = 0x2130, // meas. periodic 1 mps, high rep.
    CMD_MEAS_PERI_1_M   = 0x2126, // meas. periodic 1 mps, medium rep.
    CMD_MEAS_PERI_1_L   = 0x212D, // meas. periodic 1 mps, low rep.
    CMD_MEAS_PERI_2_H   = 0x2236, // meas. periodic 2 mps, high rep.
    CMD_MEAS_PERI_2_M   = 0x2220, // meas. periodic 2 mps, medium rep.
    CMD_MEAS_PERI_2_L   = 0x222B, // meas. periodic 2 mps, low rep.
    CMD_MEAS_PERI_4_H   = 0x2334, // meas. periodic 4 mps, high rep.
    CMD_MEAS_PERI_4_M   = 0x2322, // meas. periodic 4 mps, medium rep.
    CMD_MEAS_PERI_4_L   = 0x2329, // meas. periodic 4 mps, low rep.
    CMD_MEAS_PERI_10_H  = 0x2737, // meas. periodic 10 mps, high rep.
    CMD_MEAS_PERI_10_M  = 0x2721, // meas. periodic 10 mps, medium rep.
    CMD_MEAS_PERI_10_L  = 0x272A, // meas. periodic 10 mps, low rep.
    CMD_FETCH_DATA      = 0xE000, // readout measurements for periodic mode
    CMD_R_AL_LIM_LS     = 0xE102, // read alert limits, low set
    CMD_R_AL_LIM_LC     = 0xE109, // read alert limits, low clear
    CMD_R_AL_LIM_HS     = 0xE11F, // read alert limits, high set
    CMD_R_AL_LIM_HC     = 0xE114, // read alert limits, high clear
    CMD_W_AL_LIM_LS     = 0x6100, // write alert limits, low set
    CMD_W_AL_LIM_LC     = 0x610B, // write alert limits, low clear
    CMD_W_AL_LIM_HS     = 0x611D, // write alert limits, high set
    CMD_W_AL_LIM_HC     = 0x6116, // write alert limits, high clear
    CMD_NO_SLEEP        = 0x303E,
}etCommands;

extern SHT3X_t sht31;
/*******************************************************************************
* Function Name  : SHT3X_Init
* Description    : 传感器IIC总线初始化
* Input          : None
*                  None
* Return         : None
*******************************************************************************/
void SHT3X_Init(void);
/*******************************************************************************
* Function Name  : SHT3X_GetValue_Period
* Description    : 获取周期转化的数据
* Input          : None
*                  None
* Return         : None
*******************************************************************************/
uint8_t SHT3X_GetValue_Period(void);
/*******************************************************************************
* Function Name  : SHT3X_GetValue_Once
* Description    : 获取单次转化的数据
* Input          : None
*                  None
* Return         : None
*******************************************************************************/
uint8_t SHT3X_GetValue_Once(void);

#endif
